#pragma once

class StringHeap
{
public:
	static const uint32 HEAP_SIZE	= 4*1024*1024;
	static StringHeap* Instance(){
		static StringHeap instance;
		return &instance;
	}
	HANDLE GetSafeHeap() const {return m_heap;}
	byte* Alloc(uint32 bytes)
	{		
		byte* pData=reinterpret_cast<byte*>(::HeapAlloc(m_heap,HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,bytes+16));
		return pData;
	}
	byte* Realloc(vstr s,uint32 bytes)
	{
		byte* pNewData=reinterpret_cast<byte*>(::HeapReAlloc(m_heap,HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,s-12,bytes+16));
		return pNewData;
	}
	bool Free(vstr s)
	{
		return ::HeapFree(m_heap,0,s-12) ? true : false;
	}
	void Dispose() { ::HeapDestroy(m_heap); }

private:
	StringHeap(){m_heap=::HeapCreate(HEAP_GENERATE_EXCEPTIONS,HEAP_SIZE,0);}
	HANDLE	m_heap;
};